package com.breaker.kata.tool.mysql;

import com.wix.mysql.EmbeddedMysql;
import com.wix.mysql.config.MysqldConfig;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

import static com.wix.mysql.EmbeddedMysql.anEmbeddedMysql;
import static com.wix.mysql.ScriptResolver.classPathScripts;
import static com.wix.mysql.config.MysqldConfig.aMysqldConfig;
import static com.wix.mysql.distribution.Version.v5_7_10;

public class MysqlDBConfig {
    private static EmbeddedMysql mysqld;

    @BeforeAll
    static void beforeAll() {
        MysqldConfig config = aMysqldConfig(v5_7_10)
                .withPort(3307)
                .withUser(TestEnvConfig.mysqlUserName, TestEnvConfig.mysqlPassword)
                .build();
        mysqld = anEmbeddedMysql(config)
                .addSchema(TestEnvConfig.mysqlDatabaseName, classPathScripts("db/*.sql"))
                .start();
    }

    @AfterAll
    static void afterAll() {
        if (mysqld != null) {
            mysqld.stop();
        }
    }
}
